package com.lanxin.oa.message.dao;

import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.XxDuanxiaoxi;
import com.lanxin.bean.XxXiaoxijieshou;
import com.lanxin.util.PageBean;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Repository
public class DuanxiaoxiDaoImpl extends BaseDaoImpl implements DuanxiaoxiDao {
    @Override
    public PageBean<XxDuanxiaoxi> listDaunxiaoxi(Integer page, Integer pageSize, Integer creator) {
        String hql="from XxDuanxiaoxi duanxiaoxi " +
                "left join fetch duanxiaoxi.xiaoxijieshou xxjs " +
                "left join fetch xxjs.employee " +
                "where duanxiaoxi.creator="+creator;
        return super.pageFenYE(hql,page,pageSize);
    }

    @Override
    public PageBean<XxDuanxiaoxi> pageDuanxiaoxi(Integer page, Integer pageSize, Integer creator, String biaoti,
                                                 Integer jieshouren, Date startDate, Date endDate) {
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        String hql="select distinct duanxiaoxi from XxDuanxiaoxi duanxiaoxi " +
                "left join fetch duanxiaoxi.xiaoxijieshou xxjs left join fetch xxjs.employee " +
                "where 1=1 and duanxiaoxi.creator="+creator;
        if(biaoti!=null && !"".equals(biaoti)){
            hql = hql+" and duanxiaoxi.biaoti like '%"+biaoti+"%'";
        }
        if(jieshouren!=null && jieshouren>0){
            hql = hql+" and xxjs.jieshouren="+jieshouren;
        }
        if(startDate!=null && !"".equals(startDate)){
            hql = hql+" and duanxiaoxi.createDate > '"+sim.format(startDate)+"'";
        }
        if(endDate!=null && !"".equals(endDate)){
            hql = hql+" and duanxiaoxi.createDate < '"+sim.format(endDate)+"'";
        }
        if(startDate!=null && !"".equals(startDate) && endDate!=null && !"".equals(endDate)){
            hql = hql+" and duanxiaoxi.createDate between '"+sim .format(startDate)+"' and '"+sim.format(endDate)+"'";
        }
        return super.pageFenYE(hql,page,pageSize);
    }

    @Override
    public PageBean<XxXiaoxijieshou> xiaoxijieshou(Integer page, Integer pageSize, Integer jieshouren) {
        String hql="from XxXiaoxijieshou xxjs left join fetch xxjs.duanxiaoxi dxx " +
                "left join fetch dxx.emp where xxjs.jieshouren="+jieshouren;
        return super.pageFenYE(hql,page,pageSize);
    }

    @Override
    public PageBean<XxXiaoxijieshou> pageDuanxiaoxi(Integer page, Integer pageSize, String biaoti,
                                                 Integer jieshouren, Date startDate, Date endDate, Integer jieshourens) {
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        String hql="select distinct xxjs from XxXiaoxijieshou xxjs left join fetch xxjs.duanxiaoxi dxx " +
                "left join fetch dxx.emp where 1=1 and xxjs.jieshouren="+jieshourens;
        if(biaoti!=null && !"".equals(biaoti)){
            hql = hql+" and dxx.biaoti like '%"+biaoti+"%'";
        }
        if(jieshouren!=null && jieshouren>0){
            hql = hql+" and xxjs.jieshouren="+jieshouren;
        }
        if(startDate!=null && !"".equals(startDate)){
            hql = hql+" and xxjs.yuedushijian > '"+sim.format(startDate)+"'";
        }
        if(endDate!=null && !"".equals(endDate)){
            hql = hql+" and xxjs.yuedushijian < '"+sim.format(endDate)+"'";
        }
        if(startDate!=null && !"".equals(startDate) && endDate!=null && !"".equals(endDate)){
            hql = hql+" and xxjs.yuedushijian between '"+sim .format(startDate)+"' and '"+sim.format(endDate)+"'";
        }
        return super.pageFenYE(hql,page,pageSize);
    }

    @Override
    public XxXiaoxijieshou xxjsxq(Integer oid) {
        return (XxXiaoxijieshou) selectByHQL("from XxXiaoxijieshou xxjs left join fetch xxjs.duanxiaoxi dxx " +
                "left join fetch xxjs.employee left join fetch dxx.emp where xxjs.oid="+oid);
    }
}
